package com.cskaoyan.config;

import org.apache.shiro.web.session.mgt.DefaultWebSessionManager;
import org.springframework.http.HttpRequest;

import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import java.io.Serializable;

/**
 * @author LiaoLong
 * @date 2021-05-11 17:54
 */
public class CustomSessionManager extends DefaultWebSessionManager {
    @Override
    protected Serializable getSessionId(ServletRequest request, ServletResponse response) {
        HttpServletRequest request1 = (HttpServletRequest) request;

        String adminSessionId = request1.getHeader("X-cskaoyan-mall-Admin-Token");
        if (adminSessionId != null && !"".equals(adminSessionId)){
            return adminSessionId;
        }
        // 小程序端没有该请求头
        String wxSessionId = request1.getHeader("Set-Cookie");
        if (wxSessionId != null && !"".equals(wxSessionId)){
            return wxSessionId;
        }
        return super.getSessionId(request, response);
    }
}
